@extends('layouts.weipai')

@section('title', 'Weipai')

@section('sidebar')
@stop

@section('content')
    <div data-am-widget="list_news" class="am-list-news am-list-news-default">
        <!--列表标题-->
        <div class="am-list-news-hd am-cf">
            <h2>视频列表</h2>
        </div>
        <div class="am-list-news-bd">
            <ul class="am-list">
                @foreach($weipais as $weipai)
                <li class="am-g">
                    <p>
                        {{$weipai['account']}}{{$weipai['nickname']}}
                        <a target="_blank" href="/weipai/see?url={{$weipai['url']}}" class="am-list-item-hd "><small>在线观看</small></a>
                        <a target="_blank" href="{{$weipai['url']}}" class="am-list-item-hd "><small>下载</small></a>
                    </p>
                </li>
                @endforeach
            </ul>
        </div>
        <!--更多在底部-->
        <div class="am-list-news-ft">
            <a class="am-list-news-more am-btn am-btn-default" data-page="1" data-perpage="10" href="javascript:void(0);">查看更多 &raquo;</a>
        </div>
    </div>
@stop

@section('js')
    <script>
        $(document).ready(function () {
            $(".am-list-news-more").on('click', function(){

                var $this = $(this);
                var page  = $this.data('page');
                var perpage  = $this.data('perpage');

                $.post('weipai/ajaxGetVideo',{
                    page : page,
                    perpage : perpage
                }, function(data){
                    if (data.code == 0) {
                        var weipais = data.data;
                        var str = '';
                        for( var i = 0;  i < weipais.length; i++ ){
                            str+= '<li class="am-g">';
                            str+= '<p>' + weipais[i].account + ' ' + weipais[i].nickname;
                            str+= '<a target="_blank" href="/weipai/see?url=' + weipais[i].url + '" class="am-list-item-hd "><small>在线观看</small></a>';
                            str+= '&nbsp;<a target="_blank" href="' + weipais[i].url + '" class="am-list-item-hd "><small>下载</small></a>';
                            str+= '&nbsp;<a data-value="1" data-id="'+weipais[i].id+'" href="javascript:void(0);" class="am-list-item-hd makeHeard"><small>赞</small></a>';
                            str+= '&nbsp;<a data-value="-1" data-id="'+weipais[i].id+'" href="javascript:void(0);" class="am-list-item-hd makeHeard"><small></small></a>';
                            str+= '&nbsp;<label id="label_"' + weipais[i].id +'>' + weipais[i].heart + '</label>';
                            str+= '</p>';
                            str+= '</li>';
                        }
                        $(".am-list").append(str);
                        $this.data('page', parseInt(page) + 1);

                        $('.makeHeard').on('click', function(){
                            var $this = $(this);
                            var id = $this.data('id');
                            var value = $this.data('value');
                            $.post('weipai/ajaxAddHeart', {
                                id : id,
                                value : value
                            }, function(data){
                                if (data.code == 0) {
                                    $("#label_" + id).html(data.data.heart);
                                }
                            }, 'json');
                        });

                    }
                }, 'json');
            });
            $(".am-list-news-more").click();
        });
    </script>
@stop